import fs from '@ohos.file.fs';
import window from '@ohos.window';
import db from '../common/core/db';
import dict from '../common/core/dict';
import utils from '../common/core/utils';
import logger from '../common/core/logger';
import current from '../common/core/current';
import UIAbility from '@ohos.app.ability.UIAbility';
import emoteClient from '../common/http/emoteClient';
import serviceCache from '../common/card/serviceCache';
import { globalData } from '../common/core/globalData';

export default class EntryAbility extends UIAbility {
  onCreate() {
    globalData.abilityContext = this.context;
    globalData.filesDir = this.context.filesDir;
    globalData.resourceMana = this.context.resourceManager;
    logger.init(this.context.filesDir);
    let root = `${this.context.filesDir}/${this.context.applicationInfo.name}`;
    fs.access(root).then((res) => {
      if (!res)
        fs.mkdir(root);
    });
  }

  onWindowStageCreate(windowStage: window.WindowStage) {
    utils.setLayoutFullScreen(windowStage, dict.COLOR_WHITE, dict.COLOR_BLACK, dict.COLOR_LIKE_WHITE, dict.COLOR_BLACK);
    db.createInstance(this.context);
    current.instance.loadInfo();
    emoteClient.loadCache();
    serviceCache.createInstance(this.context);
    utils.createRdbStore(this.context);
    windowStage.loadContent('pages/Index');
  }
}